﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Polaris.Domain.Interfaces.Admin;
using Polaris.Domain.Model.Dto.Tag.Request;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace Polaris.WebApi.Controllers.Admin
{
    /// <summary>
    /// 标签控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TagController : BaseController
    {
        private readonly ITag _tag;

        public TagController(ITag tag)
        {
            _tag = tag;
        }

        /// <summary>
        /// 创建标签
        /// </summary>
        /// <param name="create"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CreateTag(CreateTagInfoRequest create)
        {
            await _tag.CreateTag(create, null);
            return SUCCESS("OK");
        }

        /// <summary>
        /// 删除标签
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleteTag(string id)
        {
            await _tag.DeleteTag(id, null);
            return SUCCESS("OK");
        }

        /// <summary>
        /// 修改标签
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdateTag(UpdateTagInfoRequest update)
        {
            await _tag.UpdateTag(update, null);
            return SUCCESS("OK");
        }

        /// <summary>
        /// 获取标签列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetTagList([FromQuery] QueryTagRequest query)
        {
            var result = await _tag.GetTagList(query);
            return SUCCESS(result);
        }

        /// <summary>
        /// 根据id获取标签
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetTagById(string id)
        {
            var result = await _tag.GetTagById(id);
            return SUCCESS(result);
        }

        /// <summary>
        /// 根据字典code来获取标签类型数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetTagByType(string type)
        {
            var result = await _tag.GetTagByType(type);
            return SUCCESS(result);
        }
    }
}
